package com.aaa.controller;

import com.aaa.pojo.*;
import com.aaa.service.MessageSendService;
import com.aaa.service.UserRightService;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@SessionAttributes
@ResponseBody
public class LoanAdminController {
    @Autowired
    private UserRightService userRightService;
    @Autowired
    private MessageSendService messageSendService;
    // 查询 网贷审核 分页
    @RequestMapping(value = "/loanAdmin/{currentPage}/{pageSize}",method = RequestMethod.GET)
    public PageInfo<UserRight> getChangePage(@PathVariable(name = "currentPage") int currentPage, @PathVariable(name = "pageSize") int pageSize){
        return userRightService.getChangeByPage(currentPage, pageSize);
    }
    //修改  审核通过 消息发送
    @RequestMapping("/loanAdminUpdate1/{ml_id}/{uid}")
    public String update1(@PathVariable(name = "ml_id") String ml_id, @PathVariable(name = "uid") int uid, HttpSession session, Message message){
        //获取管理员id
        int id = (Integer) session.getAttribute("uid");
        //获取管理员姓名
        PersonName personName = messageSendService.selectByUid(id);
        message.setSender(personName.getPname());
        //获取用户id
        message.setUid(uid);
        //消息发送
        messageSendService.insert1(message);
        //审核通过
        boolean update = userRightService.update1(ml_id);
        return JSONArray.toJSONString(update);
    }
    //修改  审核不通过 消息发送
    @RequestMapping("/loanAdminUpdate2/{ml_id}/{uid}")
    public String update2(@PathVariable(name = "ml_id") String ml_id,@PathVariable(name = "uid") int uid, HttpSession session, Message message){
        //获取管理员id
        int id = (Integer) session.getAttribute("uid");
        //获取管理员姓名
        PersonName personName = messageSendService.selectByUid(id);
        message.setSender(personName.getPname());
        //获取用户id
        message.setUid(uid);
        //消息发送
        messageSendService.insert2(message);
        //审核不通过
        boolean update = userRightService.update2(ml_id);
        return JSONArray.toJSONString(update);
    }

    //  提醒还款 消息发送
    @RequestMapping("/loanAdminUpdate3/{ml_id}/{uid}")
    public String update3(@PathVariable(name = "ml_id") String ml_id,@PathVariable(name = "uid") int uid, HttpSession session, Message message){
        //获取管理员id
        Integer uid1 = (Integer) session.getAttribute("uid");
        //获取管理员姓名
        PersonName personName = messageSendService.selectByUid(uid1);
        message.setSender(personName.getPname());
        //获取用户id
        message.setUid(uid);
        //消息发送
        messageSendService.insert3(message);
        return JSONArray.toJSONString(true);
    }

    // 查询 网贷信息 分页
    @RequestMapping("/loanInfo/{currentPage}/{pageSize}")
    public PageInfo<LoanInfo> getChangePageInfo(@PathVariable(name = "currentPage") int currentPage, @PathVariable(name = "pageSize") int pageSize){
        PageInfo<LoanInfo> changeByPageInfo = userRightService.getChangeByPageInfo(currentPage, pageSize);
        return changeByPageInfo;
    }
}
